package cn.wolfcode.restful.controller;

import cn.wolfcode.restful.domain.Employee;
import cn.wolfcode.restful.uilt.JsonResult;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;


@RestController // --->@Controller + @ResponseBody
public class EmployeeController {

    /**
     * 需求:查询某个部门下的所有员工
     *
     */
    @GetMapping("/employees/{deptId}")
    public List<Employee> list(@PathVariable Long deptId){
        return Arrays.asList(
                new Employee(1L, "aaa","1", new BigDecimal(3000),deptId,23,4)
                ,new Employee(2L, "bbb","1", new BigDecimal(3500),deptId,25,4));
    }

    /**
     * 需求:查询所有员工工资集合
     *
     */
    @GetMapping("/employees")
    public List<BigDecimal> wagesList(){
        List<Employee> employees = Arrays.asList(
                new Employee(1L, "aaa","1",  new BigDecimal(3000), 1L, 23,4)
                , new Employee(2L, "bbb","1",  new BigDecimal(3500), 1L, 25,4));
        ArrayList<BigDecimal> bigDecimals = new ArrayList<>();
        for (Employee employee : employees) {
            bigDecimals.add(employee.getWages());
        }
        return bigDecimals;
    }

    /**
     * 需求: 查询某个员工某个月工资
     */
    @GetMapping("/employees/{id}/{months}")
    public BigDecimal getWages(@PathVariable Long id, @PathVariable Integer months){
        Employee employee = new Employee(id, "aaa","1", new BigDecimal(3000), 1L, 23, months);
        return employee.getWages();
    }

    /**
     * 需求: 用户登录操作
     */
    @GetMapping("/employees/login/{name}/{password}")
    public JsonResult login(@PathVariable String name,@PathVariable String password){
        if ("admin".equals(name) && "123".equals(password)){
            return new JsonResult(200,"登录成功",null);
        }
        return new JsonResult(500,"登录失败",null);
    }

    /**
     * 需求: 用户注销操作
     */
    @GetMapping("/employees/logout")
    public JsonResult logout(){
        return new JsonResult(200,"注销成功",null);
    }

    /**
     * 需求: 按照用户名查询
     */
    @GetMapping("/employees/getName/{name}")
    public List<Employee> getName(@PathVariable String name){

        return Arrays.asList(
                new Employee(2L, name,"1", new BigDecimal(3000), 1L, 23, 3),
                new Employee(3L, name,"2", new BigDecimal(3000), 1L, 23, 3));
    }

    /**
     * 需求: 按照年龄查询
     */
    @GetMapping("/employees/getAge/{age}")
    public List<Employee> getAge(@PathVariable Integer age){

        return Arrays.asList(
                new Employee(2L, "张三","1", new BigDecimal(3000), 1L, age, 3),
                new Employee(3L, "李四","2", new BigDecimal(3000), 1L, age, 3));
    }
}
